package leetcodecompetition.D359AC;

import java.util.List;

/**
 * @Author: Siantar
 * @Date: 2023-08-20-11:00
 * @Description: 1.0
 */
public class T7006 {
    public int maximizeTheProfit(int n, List<List<Integer>> offers) {
        int[] dp = new int[n + 1];
        offers.sort((a, b) -> a.get(1) - b.get(1));
        int d = 0;
        for (int i = 0; i < n; i++) {
            dp[i + 1] = dp[i];
            while (d < offers.size() && offers.get(d).get(1) <= i) {
                int start = offers.get(d).get(0), value = offers.get(d).get(2);
                dp[i+1]=Math.max(dp[i+1],dp[start]+value);
                d++;
            }
        }
        return dp[n];
    }
}
